/*
 * FileName：SysUserCtrl.java 
 * <p>
 * Copyright (c) 2017-2020 <a href="https://www.smartwx.info">hermit(1154808491@qq.com)</a>.
 * <p>
 * Licensed under the GNU General Public License, Version 3 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * <p>
 * http://www.gnu.org/licenses/gpl-3.0.html
 * <p>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * 
 */
package com.smart.primary.sys.ctrl;

import com.smart.common.BaseCtrl;
import com.smart.common.util.*;
import com.smart.sys.entity.SysUser;
import com.smart.sys.service.ISysUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.List;

/**
 * 用户信息
 *
 * @author hermit
 * @version 2.0
 * @date 2018-12-30 22:26:32
 */
@RestController
@RequestMapping("/sys/user")
@Api(description = "用户信息")
public class SysUserCtrl extends BaseCtrl {
    @Resource
    private ISysUserService sysUserService;

    /**
     * 列表
     */
    @GetMapping("/list")
    @ApiOperation(value = "获取列表信息")
    public AjaxResult list(SysUser sysUser) throws Exception {
        List<SysUser> sysUserList = sysUserService.queryListByPage(sysUser);
        return getResult(sysUser, sysUserList);
    }

    /**
     * 信息
     */
    @GetMapping("/info")
    @ApiOperation(value = "获取详情信息")
    public AjaxResult info(SysUser sysUser) throws Exception {
		SysUser one =sysUserService.queryObject(sysUser);
        return AjaxResult.success(one);
    }

    /**
     * 保存
     */
    @PostMapping("/save")
    @ApiOperation(value = "保存")
    public AjaxResult save(SysUser sysUser) throws Exception {
		sysUserService.insert(sysUser);
        return AjaxResult.saveSuccess();
    }

    /**
     * 修改
     */
    @PostMapping("/update")
    @ApiOperation(value = "修改")
    public AjaxResult update(SysUser sysUser) throws Exception {
		sysUserService.update(sysUser);
        return AjaxResult.updateSuccess();
    }

    /**
     * 删除
     */
    @PostMapping("/delete")
    @ApiOperation(value = "删除")
    public AjaxResult delete(SysUser sysUser) throws Exception {
		sysUserService.delete(sysUser);
        return AjaxResult.deleteSuccess();
    }

    /**
     * 批量删除
     */
    @PostMapping("/deleteBatch")
    @ApiOperation(value = "批量删除")
    public AjaxResult deleteBatch(@RequestParam("userIds[]") String[] userIds) throws Exception {
        sysUserService.deleteBatch(Arrays.asList(userIds));
        return AjaxResult.deleteSuccess();
    }

    /**
     * 重置密码
     */
    @PostMapping("/reset/password")
    @ApiOperation(value = "批量删除")
    public AjaxResult resetPassword(@RequestParam("userIds[]") String[] userIds) throws Exception {
        sysUserService.resetPassword(Arrays.asList(userIds));
        return AjaxResult.deleteSuccess();
    }
}
